﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case ("sua"):
                System.Data.DataTable dt = ThanhVien.getFullTV(e.CommandArgument.ToString());
                txtTenDN.Text = dt.Rows[0]["TenDN"].ToString();
                txtHoten.Text = dt.Rows[0]["Hoten"].ToString();
                txtDiachi.Text = dt.Rows[0]["diachi"].ToString();
                txtEmail.Text = dt.Rows[0]["email"].ToString();
                txtSdt.Text = dt.Rows[0]["sdt"].ToString();
                ddlLoai.SelectedValue = dt.Rows[0]["LOAITV"].ToString();
                btnUpdate.Text = "Cập nhật";
                btnUpdate.CommandArgument = "sua";
                pnEdit.Visible = true;

                break;
        }

    }
    protected void lbtnDong_Click(object sender, EventArgs e)
    {
        pnEdit.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {



    }

    protected void Button2_Click(object sender, EventArgs e)
    {


    }
    private void capnhat()
    {


    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        txtTenDN.Text = txtDiachi.Text = txtEmail.Text = txtHoten.Text = txtSdt.Text = txtMK.Text = "";
        btnUpdate.Text = "Thêm";
        btnUpdate.CommandArgument = "them";
        pnEdit.Visible = true;
    }
    protected void btnCapnhat_Click(object sender, EventArgs e)
    {
        switch (btnUpdate.CommandArgument)
        {
            case ("sua"):
                ThanhVien tv = new ThanhVien();
                tv.TenDN = txtTenDN.Text;
                ObjectUpdate objUp = new ObjectUpdate();
                objUp.Add("hoten", txtHoten.Text);
                objUp.Add("diachi", txtDiachi.Text);
                objUp.Add("email", txtEmail.Text);
                objUp.Add("sdt", txtSdt.Text);
                objUp.Add("loaitv", ddlLoai.SelectedValue);
                if (!txtMK.Text.Equals(""))
                {
                    objUp.Add("matkhau", txtMK.Text.MD5().MD5());
                }

                if (tv.CapNhat(objUp))
                {
                    GridView1.DataBind();
                    pnEdit.Visible = false;
                }
                break;
            case ("them"):
                ThanhVien themtv = new ThanhVien();
                themtv.TenDN = txtTenDN.Text;
                themtv.MK = txtMK.Text.MD5().MD5();
                themtv.HoTen = txtHoten.Text;
                themtv.SDT = txtSdt.Text;
                themtv.Email = txtEmail.Text;
                themtv.DiaChi = txtDiachi.Text;
                if (themtv.ThemThanhVien())
                {
                    GridView1.DataBind();
                    pnEdit.Visible = false;
                }
                break;
        }
    }
}